package com.zsd.android.okhttplib;

import java.util.HashMap;

public class Request {

    public static final String GET = "GET";
    public static final String POST = "POST";

    private String url;
    private String requestMethod;
    private HashMap<String, String> mHeaderList;
    private RequestBody requestBody;

    public Request() {
        this(new Builder());
    }

    private Request(Builder builder) {
        this.url = builder.url;
        this.requestMethod = builder.requestMethod;
        this.mHeaderList = builder.mHeaderList;
        this.requestBody = builder.requestBody;
    }

    public String getUrl() {
        return url;
    }

    public String getRequestMethod() {
        return requestMethod;
    }

    public HashMap<String, String> getHeaderList() {
        return mHeaderList;
    }

    public RequestBody getRequestBody() {
        return requestBody;
    }

    public static final class Builder {

        private String url;
        private String requestMethod;
        private HashMap<String, String> mHeaderList;
        private RequestBody requestBody;

        public Builder() {
            requestMethod = GET;
            mHeaderList = new HashMap<>();
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder get() {
            requestMethod = GET;
            return this;
        }

        public Builder post(RequestBody requestBody) {
            requestMethod = POST;
            this.requestMethod = requestMethod;
            return this;
        }

        public Builder addRequestHeader(String key, String value) {
            mHeaderList.put(key, value);
            return this;
        }

        public Request build() {
            return new Request(this);
        }
    }
}
